#include "Encrypt.h"

void Encrypt(void* pSrc, void** pDst, long long len)
{
    if (NULL != pSrc && len > 0)
    {
        char* pTmpDst = (char*)malloc(len);
        char* pTmpSrc = (char*) pSrc;
        if(NULL != pTmpDst)
        {
            long long nKey = ENCRYPT_CODE;
            char* pKey = (char*)&nKey;
            int nKeyPost = 0;
            int nSrcPost = 0;
            int nKeyLen = sizeof(nKey);

            while (nSrcPost < len)
            {
                pTmpDst[nSrcPost] = pTmpSrc[nSrcPost] ^ pKey[nKeyPost];
                nSrcPost++;
                nKeyPost++;
                if(nKeyPost == nKeyLen)
                {
                    nKeyPost = 0;
                }
            }
            *pDst = pTmpDst;
        }
    }
}

void Decrypt(void* pSrc, void** pDst, long long len)
{
    Encrypt(pSrc, pDst, len);
}

void encrypt(void* pSrc, long long len)
{
    char* pTmpSrc = pSrc;
    for (size_t i = 0; i < len; i++)
    {
        pTmpSrc[i] = ~pTmpSrc[i];
    }
}